package com.apartment.own.controller;

import java.util.List;

import com.apartment.own.domain.OwnAccountInstallment;
import com.apartment.own.request.bills.BillPreviewDTO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.apartment.common.annotation.Log;
import com.apartment.common.core.controller.BaseController;
import com.apartment.common.core.domain.AjaxResult;
import com.apartment.common.enums.BusinessType;
import com.apartment.own.domain.OwnAccountDetails;
import com.apartment.own.service.IOwnAccountDetailsService;
import com.apartment.common.utils.poi.ExcelUtil;
import com.apartment.common.core.page.TableDataInfo;

/**
 * 账单详情Controller
 * 
 * @author @Dog_E
 * @date 2020-08-28
 */
@RestController
@RequestMapping("/own/details")
@Api(value = "账单详情",tags = "账单详情")
public class OwnAccountDetailsController extends BaseController
{
    @Autowired
    private IOwnAccountDetailsService ownAccountDetailsService;

    /**
     * 查询账单详情列表
     */
    @PreAuthorize("@ss.hasPermi('own:details:list')")
    @GetMapping("/list")
    public TableDataInfo list(OwnAccountDetails ownAccountDetails)
    {
        startPage();
        List<OwnAccountDetails> list = ownAccountDetailsService.selectOwnAccountDetailsList(ownAccountDetails);
        return getDataTable(list);
    }

    /**
     * 导出账单详情列表
     */
    @PreAuthorize("@ss.hasPermi('own:details:export')")
    @Log(title = "账单详情", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(OwnAccountDetails ownAccountDetails)
    {
        List<OwnAccountDetails> list = ownAccountDetailsService.selectOwnAccountDetailsList(ownAccountDetails);
        ExcelUtil<OwnAccountDetails> util = new ExcelUtil<OwnAccountDetails>(OwnAccountDetails.class);
        return util.exportExcel(list, "details");
    }

    /**
     * 获取账单详情详细信息
     */
    @PreAuthorize("@ss.hasPermi('own:details:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(ownAccountDetailsService.selectOwnAccountDetailsById(id));
    }

    /**
     * 新增账单详情
     */
    @PreAuthorize("@ss.hasPermi('own:details:add')")
    @Log(title = "账单详情", businessType = BusinessType.INSERT)
    @PostMapping
//    @ApiOperation("账单详情")
    public AjaxResult add(@RequestBody OwnAccountDetails ownAccountDetails)
    {
        return toAjax(ownAccountDetailsService.insertOwnAccountDetails(ownAccountDetails));
    }

    /**
     * 修改账单详情
     */
    @PreAuthorize("@ss.hasPermi('own:details:edit')")
    @Log(title = "账单详情", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OwnAccountDetails ownAccountDetails)
    {
        return toAjax(ownAccountDetailsService.updateOwnAccountDetails(ownAccountDetails));
    }

    /**
     * 删除账单详情
     */
    @PreAuthorize("@ss.hasPermi('own:details:remove')")
    @Log(title = "账单详情", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(ownAccountDetailsService.deleteOwnAccountDetailsByIds(ids));
    }


    /**
     * @Description: 账单预览
     * @param billPreviewDTO:账单预览参数
     * @return: com.apartment.common.core.domain.AjaxResult
     * @Author: @Dog_E
     * @Date: 2020/9/15 0015 16:36
     **/
    @PreAuthorize("@ss.hasPermi('own:details:list')")
    @GetMapping("/billPreview")
    @ApiOperation("账单预览")
    public AjaxResult billPreview(@RequestBody BillPreviewDTO billPreviewDTO){
        List<OwnAccountInstallment> ownAccountInstallments = ownAccountDetailsService.billPreview(billPreviewDTO);
        return AjaxResult.success(ownAccountInstallments);
    }
}
